﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Golf.WebUI.AdminShow.CommoditiesMmanagement
{
    public partial class Golf_Product_cuxiao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int Id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(Id);
                }
            }
        }

        private void ShowInfo(int Id)
        {

            Golf.BLL.Golf_Product bll = new Golf.BLL.Golf_Product();
            Golf.Model.Golf_Product model = bll.GetModel(Id);
            this.lblId.Text = model.Id.ToString();

            this.chkIsPromotion.Checked = model.IsPromotion;
            this.txtPro_PromotionPrice.Text = model.Pro_PromotionPrice.ToString();
            this.txtPromotionStartTime.Text = model.PromotionStartTime.ToString();
            this.txtPromotionEndTime.Text = model.PromotionEndTime.ToString();
        }



        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (!PageValidate.IsDecimal(txtPro_PromotionPrice.Text))
            {
                strErr += "促销价格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtPromotionStartTime.Text))
            {
                strErr += "促销开始时间格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtPromotionEndTime.Text))
            {
                strErr += "促销结束时间格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int Id = int.Parse(this.lblId.Text);
            bool IsPromotion = this.chkIsPromotion.Checked;
            decimal Pro_PromotionPrice = decimal.Parse(this.txtPro_PromotionPrice.Text);
            DateTime PromotionStartTime = DateTime.Parse(this.txtPromotionStartTime.Text);
            DateTime PromotionEndTime = DateTime.Parse(this.txtPromotionEndTime.Text);
            Golf.BLL.Golf_Product bll = new Golf.BLL.Golf_Product();
            Golf.Model.Golf_Product model = bll.GetModel(Id);
            if (model == null) return;
            model.Id = Id;
            model.IsPromotion = IsPromotion;
            model.Pro_PromotionPrice = Pro_PromotionPrice;
            model.PromotionStartTime = PromotionStartTime;
            model.PromotionEndTime = PromotionEndTime;
            if (bll.Update(model))
            {
                Page.ClientScript.RegisterStartupScript(typeof(Page), "", "handler('添加成功！');", true);
            }
            else
            {

                Page.ClientScript.RegisterStartupScript(typeof(Page), "", "ymPrompt.errorInfo('保存失败');", true);
            }

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterStartupScript(typeof(Page), "", "handler('请点击确定取消当前操作！');", true);
        }
    }
}
